import config from "./config";
import {notification} from "antd";
import axios from "axios";

export default class Service{
    static get businessService() {
        //创建axios的对象
        let service = axios.create({
            baseURL: `${config.service.url}/api`,
            headers: {'App-Version': '0.1.0'}
        });

        service.defaults.timeout = 1200000000;
        //此处为一个全局的响应拦截器，关于拦截器的用法请查阅axios的文档
        service.interceptors.response.use(function (response) {
            return response;
        }, function (error) {
            if (error.code === 'ECONNABORTED' || !error.response) {
                notification.warning({
                    key: 'network error',
                    message: '很抱歉',
                    description: '请检查您的网络是否正常..'
                });
            }


            return Promise.reject(error);
        });

        return service;
    }

    static binomial(params,options={}){
        return Service.businessService.get(`/Calculate`,{...options,params:params})
    }

    static fractalTree(params,options={}){
        return Service.businessService.get(`/GetFractalTree`,{...options,params:params})
    }

    static twentyfour(params,options={}){
        return Service.businessService.get(`/Calculate24`,{...options,params:params})
    }

    static geneContrast(params,options={}){
        return Service.businessService.get(`/GeneContrast`,{...options,params:params})
    }

    static getBranchBound(params,options={}){
        return Service.businessService.get(`/GetBranchBound`,{...options,params:params})
    }

    static yacht(params,options={}){
        return Service.businessService.get(`/Yacht`,{...options,params:params})
    }

    static getMap(options={}){
        return Service.businessService.get(`/MapOverlay`,{...options})
    }

    static strongLine(params,options={}){
        return Service.businessService.get(`/StrongLine`,{...options,params})
    }
}